package com.tmpt.controller.action;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.googlecode.genericdao.search.Search;
import com.opensymphony.xwork2.ActionSupport;
import com.tmpt.dto.A1OperationlogDto;
import com.tmpt.dto.PaginationDto;
import com.tmpt.service.IOperationlogService;
import com.tmpt.utils.DateTool;
import com.tmpt.utils.JsonPaginationUtils;
import com.tmpt.utils.WebUtils;

@Controller
@Scope("prototype")
public class OperationlogAjaxAction extends ActionSupport{
	private int page;
	private int rows;
	private String loginName;
	private String logTypeName;
	private int orderTypeId;
	private String orderNum;
	private int logTypeId;
	private String recordDateStart;
	private String recordDateEnd;
	private String sortColumn;
	private String sortOrder;
	
	private String result;	
	
    @Resource IOperationlogService operationlogService;

    /**
	 * 分页查询商品列表
	 * @param paramMap
	 * @return
	 */
	public String queryOperationlogBySearch(){
		Search search = new Search();
		search.setPage(page-1);
		search.setMaxResults(rows);
		HttpServletResponse response = ServletActionContext.getResponse();
		
		if("desc".equals(sortOrder) && sortColumn!=null){
			search.addSort(sortColumn, true);
		}else if("asc".equals(sortOrder) && sortColumn!=null){
			search.addSort(sortColumn, false);
		}
		
		if(loginName!= null && loginName.trim() != ""){
			search.addFilterEqual("loginName", loginName);
		}
		
		if(logTypeId!=0){
			search.addFilterEqual("logType.id",logTypeId);
		}
		
		if(orderTypeId !=0){
			search.addFilterEqual("orderType", orderTypeId);
		}

		if(orderNum != null && orderNum.trim() != ""){
			search.addFilterEqual("orderNum", orderNum);
		}
		
		search.addFilterGreaterOrEqual("createDate", DateTool.string2Date(recordDateStart, "yyyy-MM-dd"));
		search.addFilterLessOrEqual("createDate", DateTool.string2DateEnd(recordDateEnd, "yyyy-MM-dd"));

		if(JsonPaginationUtils.checkDateResponseWriter(recordDateStart, recordDateEnd, response)){
			return "jsonResult";
		}
		
		HttpSession session = WebUtils.getRequest().getSession();
		session.removeAttribute("logListSearch");
		session.setAttribute("logListSearch", search.copy());

		PaginationDto<A1OperationlogDto> pagination = operationlogService.paginationBySearch(search);	

		this.result = JsonPaginationUtils.paginationToJson(pagination);

		JsonPaginationUtils.responseWriter(response, this.result);
		
		return "jsonResult";
	}

	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	 }
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public String getLoginName() {
		return loginName;
	}
	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}
	public String getLogTypeName() {
		return logTypeName;
	}
	public void setLogTypeName(String logTypeName) {
		this.logTypeName = logTypeName;
	}
	public String getRecordDateStart() {
		return recordDateStart;
	}
	public void setRecordDateStart(String recordDateStart) {
		this.recordDateStart = recordDateStart;
	}
	public String getRecordDateEnd() {
		return recordDateEnd;
	}
	public void setRecordDateEnd(String recordDateEnd) {
		this.recordDateEnd = recordDateEnd;
	}
	public String getSortOrder() {
		return sortOrder;
	}
	public void setSortOrder(String sortOrder) {
		this.sortOrder = sortOrder;
	}
	public String getSortColumn() {
		return sortColumn;
	}
	public void setSortColumn(String sortColumn) {
		this.sortColumn = sortColumn;
	}
	public int getLogTypeId() {
		return logTypeId;
	}
	public void setLogTypeId(int logTypeId) {
		this.logTypeId = logTypeId;
	}

	public int getOrderTypeId() {
		return orderTypeId;
	}

	public void setOrderTypeId(int orderTypeId) {
		this.orderTypeId = orderTypeId;
	}

	public String getOrderNum() {
		return orderNum;
	}

	public void setOrderNum(String orderNum) {
		this.orderNum = orderNum;
	}

	public IOperationlogService getOperationlogService() {
		return operationlogService;
	}

	public void setOperationlogService(IOperationlogService operationlogService) {
		this.operationlogService = operationlogService;
	}  
	
}
